/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dinner.web.eat;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import dinner.web.Eat;

/**
 * 
 * @author Bizon
 */
public class IO {
	public static String D = File.separator;

	public static String getDBForCurrentDate() {
		return getDBForDate(Calendar.getInstance());
	}

	public static String getDBForDate(Calendar c) {
		String currentDate = c.get(Calendar.DAY_OF_MONTH) + "." + (c.get(Calendar.MONTH) + 1) + "." + c.get(Calendar.YEAR);
		return getRoot() + D + "db" + D + currentDate;
	}

	public static String getRoot() {
		return "C:/Users/Bizon/Documents/NetBeansProjects/dinner_home";// System.getProperty("DINNER_HOME");
	}

	public static File getRootFile() {
		return new File(getRoot());
	}

	public static List<Eat> readDefaultMenu() {
		List<Eat> eats = new ArrayList<Eat>();
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(getRoot() + "\\Eat.db"));
			do {
				String line = reader.readLine();
				if (line != null) {
					eats.add(new Eat(line));
				} else {
					break;
				}
			} while (true);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (reader != null) {
			try {
				reader.close();
			} catch (IOException ex) {
				Logger.getLogger(IO.class.getName()).log(Level.SEVERE, null, ex);
			}
		}
		return eats;
	}

}
